/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * HistoricDespeses.java
 *
 * Created on 21-nov-2011, 18:59:01
 */
package edu.uoc.tdp.pac4.only5.gui.client.panels.connexio;

import edu.uoc.tdp.pac4.only5.exceptions.EespaisDatabaseException;
import edu.uoc.tdp.pac4.only5.gui.client.ClientSession;
import edu.uoc.tdp.pac4.only5.gui.client.model.BookingPaymentVOTableModel;
import edu.uoc.tdp.pac4.only5.gui.client.panels.AbstractPanel;
import edu.uoc.tdp.pac4.only5.manager.BookingManager;
import edu.uoc.tdp.pac4.only5.vo.BookingPaymentVO;
import java.rmi.RemoteException;
import java.util.List;



/**
 *
 * @author Gerard
 */
public class HistoricDespesesPanel extends AbstractPanel {
    
    
    private BookingManager bookingManager;
    
    /** Creates new form HistoricDespeses */
    public HistoricDespesesPanel(BookingManager bookingManager) {
        this.bookingManager = bookingManager;
        initComponents();
        fillTable();
        setLabels();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        tblHistoric = new javax.swing.JTable();
        lblHistoricDespeses = new javax.swing.JLabel();

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        tblHistoric.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        tblHistoric.setName("tblHistoric"); // NOI18N
        jScrollPane1.setViewportView(tblHistoric);

        lblHistoricDespeses.setFont(new java.awt.Font("Lucida Grande", 0, 18)); // NOI18N
        lblHistoricDespeses.setText("Històric Despeses");
        lblHistoricDespeses.setName("lblHistoricDespeses"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 767, Short.MAX_VALUE)
                    .addComponent(lblHistoricDespeses))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblHistoricDespeses)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 392, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblHistoricDespeses;
    private javax.swing.JTable tblHistoric;
    // End of variables declaration//GEN-END:variables

    
    private void fillTable(){
        try {
            List<BookingPaymentVO> bookings = bookingManager.getHistoricOfUser(ClientSession.getInstance().getUser().getUserId());
            String[] columns = {"table.historic.id", "table.historic.space", "table.historic.startTime", "table.historic.endTime", "table.historic.status" ,"table.historic.price"};
            tblHistoric.setModel(new BookingPaymentVOTableModel(bookings, columns));
            setTableHeaders(columns, tblHistoric);
        } catch (RemoteException ex) {
            showErrorMessageDialog(this, "error.generic.rmi");
        } catch(EespaisDatabaseException ex){
            showErrorMessageDialog(this, "error.generic.databaseerror");
        } 
    }
    
    @Override
    protected void setLabels() {
        lblHistoricDespeses.setText(getText("historic.title"));
    }
}
